package com.jsb.laundry.model.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jsb.laundry.model.entity.JsbPostComments;
import com.jsb.laundry.model.entity.JsbPosts;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 帖子视图
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(description = "帖子评论信息")
public class PostCommentVO implements Serializable {

    private final static Gson GSON = new Gson();

    @ApiModelProperty(value = "评论id", dataType = "int")
    private Integer id;

    @ApiModelProperty(value = "评论内容", dataType = "string")
    private String content;

    @ApiModelProperty(value = "评论用户信息", dataType = "user")
    private UserVO user;

    @ApiModelProperty(value = "是否已过赞", dataType = "Boolean")
    private Boolean hasLike;

    @ApiModelProperty(value = "创建时间", dataType = "data")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createdAt;

    @ApiModelProperty(value = "更新时间", dataType = "data")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updatedAt;

    /**
     * 包装类转对象
     *
     * @param postCommentVO
     * @return
     */
    public static JsbPostComments voToObj(PostCommentVO postCommentVO) {
        if (postCommentVO == null) {
            return null;
        }
        JsbPostComments postComment = new JsbPostComments();
        BeanUtils.copyProperties(postCommentVO, postComment);

        return postComment;
    }

    /**
     * 对象转包装类
     *
     * @param postComment
     * @return
     */
    public static PostCommentVO objToVo(JsbPostComments postComment) {
        if (postComment == null) {
            return null;
        }
        PostCommentVO postCommentVO = new PostCommentVO();
        BeanUtils.copyProperties(postComment, postCommentVO);
        return postCommentVO;
    }
}
